Implementing handler with DLL¶
Description¶
Implement those processes for the commands and events defined in the manifest as extension points.
Class methods that implement these processes are called command handler and event handler.
These handlers are implemented as public methods in the public class (hereinafter, main class) that implements the IExtension
interface.
The name of the main class and the name of the class file are arbitrary.
Implementation example¶
Here is an implementation example of the command handler when the following command is defined in the manifest.
Manifest command definition example
"extensionPoints": {
"commands": [
{
"id": "Command.SayHello",
"execFunc": "SayHello"
}
],
...
}
In the case of the above command definition example, the command handler named SayHello
specified in the extensionPoints.commands[0].execFunc
property is implemented as a public method of the main class.
Example of command handler implementation in main class
//Declaration of the namespace of the API referenced in extension development
using NextDesign.Extension;
using NextDesign.Core;
using NextDesign.Desktop;
//Main class of the entry point DLL
//Implement the IExtension interface in the main class.
//Implement the handler as a public method of this class.
public class MyExtension :IExtension
{
//command handler
public void SayHello(ICommandContext context,ICommandParams commandParams)
{
context.App.Window.UI.ShowInformationDialog("Hello !","Hello World");
}
//Extension initialization process
public void Activate(IContext context)
{
//Implement as an empty method even if there is no processing
}
//Extension termination processing
public void Deactivate(IContext context)
{
//Implement as an empty method even if there is no processing
}
}
Reference
-
See the following references for more information on the arguments passed to the Command Handler.
important
- The DLL file specified as the entry point must include one main class that implements the
IExtension
interface. - All handlers must be implemented as public methods of their main class.
Tip
- In the case of large-scale extension development, the number of handlers also increases and the implementation code of the entry point also becomes bloated.
To make the implementation code of the entry point compact, it is recommended to use the following file structure.
- Implement the actual processing in a file different from the entry point and split the file.
- The handler implemented in the entry point file calls the function implemented in another file or the class method implemented in another class.
Supplement¶
Implementation of IExtension interface in main class¶
-
In case of implementation method using .Net DLL, the DLL file specified in the entry point must have one main class that implements IExtension interface ..
-
The main class is implemented as a public class.
-
In order to implement the
IExtension
interface in the main class, implement public methods namedActivate
andDeactviate
.Activate
method: Executed once just after the extension life cycle starts.Deactivate
method: Executed once just before the end of the extension life cycle. -
In the
Activate
andDeactivate
methods, you can implement initialization processing and termination processing related to the entire extension, in addition to the processing of the handler called for each command or event.Example of initialization processing: initialization of common variables, reading of configuration files, etc. Example of termination processing: Saving status and settings files, etc.
-
Implement it as an empty method even if you do not need initialization or termination.